import request from '@/utils/request'
import defaultSettings from '@/settings'
const qs = require('qs')

export const apiUrlConfig = {
  queryUrl: `${defaultSettings.ctx.authorityApp}/s/dictInfo/search`,
  exportUrl: `${defaultSettings.ctx.authorityApp}/s/dictInfo/search`,
  delUrl: `${defaultSettings.ctx.authorityApp}/s/dictInfo/remove`,
}

// 查询字典类型列表
export function listType(query) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/dictInfo/search`,
    method: 'get',
    params: query
  })
}
// 获取详情
export function getType(id) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/dictInfo/getDictTypeData?id=${id}`,
    method: 'get'
  })
}

export function preAddOrUpdate(id) {

  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/dictInfo/initEditCache?id=${id ? id : ''}`,
    method: 'get'
  })
}

// 新增或编辑字典类型
export function addOrUpdateType(data) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/dictInfo/save`,
    method: 'post',
    data: data
  })
}

// 删除字典类型
export function delType(ids) {
  const data = (ids && ids.indexOf(',') > -1) ? ids.join(',') : ids;
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/dictInfo/remove?ids=${data}`,
    method: 'post'
  })
}

// 校验字典类型
export function checkDictType(data) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/dictInfo/checkDictTypeUnique`,
    method: 'get',
    params:data
  })
}
